package com.lex.controller;

import com.lex.common.annoatation.SysLog;
import com.lex.common.api.CommonResult;
import com.lex.common.enums.BusinessType;
import com.lex.entity.params.RoleListQueryParams;
import com.lex.entity.params.UpdateRoleStateParams;
import com.lex.entity.role.RoleDto;
import com.lex.service.RoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
@Tag(name = "RoleController", description = "角色管理接口")
public class RoleController {

    @Autowired
    private RoleService roleService;


    @Operation(summary = "获取所有角色列表")
    @RequestMapping(value = "/getRoleListByPage",method = RequestMethod.GET)
    public CommonResult getRoleList(RoleListQueryParams queryParams,
                                    @RequestParam(defaultValue = "10") Integer pageSize,
                                    @RequestParam(defaultValue = "1") Integer page) {
        return roleService.getRolelist(queryParams, pageSize, page);
    }

    @Operation(summary = "添加角色")
    @SysLog(title = "添加角色", businessType = BusinessType.INSERT)
    @RequestMapping(value = "/addRole", method = RequestMethod.POST)
    public CommonResult addRole(@RequestBody RoleDto addRoleDto){
        return roleService.addRole(addRoleDto);
    }

    @Operation(summary = "更新角色")
    @SysLog(title = "更新角色", businessType = BusinessType.UPDATE)
    @RequestMapping(value = "/updateRole", method = RequestMethod.PUT)
    public CommonResult updateRole(@RequestBody RoleDto updateRoleDto){
        return roleService.updateRole(updateRoleDto);
    }

    @Operation(summary = "删除角色")
    @SysLog(title = "删除角色", businessType = BusinessType.DELETE)
    @RequestMapping(value = "/deleteRole/{roleId}", method = RequestMethod.DELETE)
    public CommonResult deleteRole(@PathVariable Long roleId){
       return roleService.deleteRole(roleId);
    }

    @Operation(summary = "获取角色列表,用户添加用户时选择角色")
    @RequestMapping(value = "/getRoleList", method = RequestMethod.GET)
    public CommonResult getRoleList(){
        return roleService.getAllRoleList();
    }

    @Operation(summary = "修改角色状态")
    @SysLog(title = "修改角色状态", businessType = BusinessType.UPDATE)
    @RequestMapping(value = "/updateRoleStatus", method = RequestMethod.POST)
    public CommonResult updateRoleStatus(@Validated @RequestBody UpdateRoleStateParams updateRoleStateDto){
        return roleService.updateRoleStatus(updateRoleStateDto);
    }

}
